setProvince();
setOneClass(2);

function setProvince()
{
	Ts_areaInfo.getAreaClassByUpId('000000000000000',function(data){
		DWRUtil.removeAllOptions('province');
		DWRUtil.addOptions('province',{'':'请选择'});
		DWRUtil.addOptions('province',data);
	})
}
function setCitys(prov)
{
   var provence=prov;
	 Ts_areaInfo.getAreaClassByUpId(provence,function(data){
		DWRUtil.removeAllOptions('eparchy_code');
		DWRUtil.addOptions('eparchy_code',{'':'请选择'});
		DWRUtil.addOptions('eparchy_code',data);
		DWRUtil.removeAllOptions('city_code');
		DWRUtil.addOptions('city_code',{'':'请选择'});
	});
}

function setAreas(city_id){
	Ts_areaInfo.getAreaClassByUpId(city_id,function(data){
	 	DWRUtil.removeAllOptions('city_code');
     	DWRUtil.addOptions('city_code',{'':'请选择'});
	 	DWRUtil.addOptions('city_code',data);
	});
}





function setOneClass(val){
	Ts_categoryInfo.getCatClassByUpId("000000000000000","1",setSort1);
}
function setSort1(map_data)
{
	var factory = $("sort1");
	DWRUtil.removeAllOptions("sort1");
	DWRUtil.addOptions("sort1",{'':'请选择'});
	DWRUtil.addOptions("sort1",map_data);
}
 

  
  var class_type = "1";
// 设置二级分类
function setSecondClass(val) {
	var up_class_id = val; 
 
	Ts_categoryInfo.getCatClassByUpId(up_class_id, class_type, setSort2);
}
function setSort2(map_data) {
	DWRUtil.removeAllOptions("sort2");
	DWRUtil.addOptions("sort2",{'':'请选择'});
	DWRUtil.addOptions("sort2", map_data);
	$("sort3").style.display = "none";
	var item = $("sort2").length;

}
// 设置三级分类
function setTherdClass(val) {
	var up_class_id = val;
	Ts_categoryInfo.getCatClassByUpId(up_class_id, class_type, setSort3);
}
function setSort3(map_data) {
	if (map_data != null) {
		DWRUtil.removeAllOptions("sort3");
		DWRUtil.addOptions("sort3",{'':'请选择'});
		DWRUtil.addOptions("sort3", map_data);

	}
}
 
function setTypeName1(obj){
	  var idx = obj.value;
		$("class_id3").value="";
		$("class_id2").value="";
		$("class_id1").value=idx;
		Ts_categoryInfo.getCatNameById(idx,setClassName1);
		//$("class_name").value=DWRUtil.getText(obj.name);
		//$("count").value=obj.name;
}
function setClassName1(val) {
	$("name3").innerHTML = '';
	$("name2").innerHTML = '';
	$("name1").innerHTML = val;
	$("name0").innerHTML = '';
	
	
}

function setTypeName2(obj){
	  var idx = obj.value;
	  $("class_id3").value="";
		$("class_id2").value=idx;
		Ts_categoryInfo.getCatNameById(idx,setClassName2);
		//$("class_name").value=DWRUtil.getText(obj.name);
		//$("count").value=obj.name;
}
function setClassName2(val) {
	$("name3").innerHTML = '';
	$("name2").innerHTML = " > "+val;
}
function setTypeName3(obj){
	  var idx = obj.value;
		$("class_id3").value=idx;
		Ts_categoryInfo.getCatNameById(idx,setClassName3);
		//$("class_name").value=DWRUtil.getText(obj.name);
		//$("count").value=obj.name;
}function setClassName3(val) {
	$("name3").innerHTML = " > "+val;
}



 
 //验证只能输入数字和小数点
function clearNoNum(obj){
	//先把非数字的都替换掉，除了数字和.
	obj.value = obj.value.replace(/[^\d.]/g,"");
	//必须保证第一个为数字而不是.
	obj.value = obj.value.replace(/^\./g,"");
	//保证只有出现一个.而没有多个.
	obj.value = obj.value.replace(/\.{2,}/g,".");
	//保证.只出现一次，而不能出现两次以上
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}
// 检测是否为合法数据
function isNum(str) {
	return (str.search(/^\d+(\.\d+)?$/) != -1);
}
function trim(str){
    return str.replace(/(^\s*)|(\s*$)/g,"");
  }//去掉空格



//========================提交验证========================
function  submitForm()
{
	 
	 var cust_aim = document.addForm.cust_name.value;
	  if(null == cust_aim || cust_aim == "")
	  {
	  	alert("公司名称不能为空!");
	  	document.getElementById("cust_name").focus();
	  	return false;
	  }
	 
	  var types = document.addForm.cust_type.value;
	  if(null == types || types == "请选择")
	  {
	  	alert("请选择公司类型!");
	  	document.getElementById("cust_type").focus();
	  	return false;
	  }
	  
	  
	  //提交时把企业类型拼串
	  document.getElementById("client_status").value = "";
	   
	  for (var i=1;i<=5;i++){
			if(document.getElementById("client_status"+i).checked==true){
				document.getElementById("client_status").value += document.getElementById("client_status"+i).value + "|" ;
				
			}
	  }

	 
	   var types = document.addForm.client_status.value;
	  if(null == types || types == "")
	  {
	  
	  	alert("请选择经营模式!");
		document.getElementById("client_status").focus();
	  	return false;
	  }
	  
	  //地区拼串
		var area_attr_str = "";
		if(document.getElementById("province").value!=""){
			area_attr_str += document.getElementById("province").value+"|";
			if(document.getElementById("eparchy_code").value!=""){
				area_attr_str += document.getElementById("eparchy_code").value+"|";
				if(document.getElementById("city_code").value!=""){
					area_attr_str += document.getElementById("city_code").value+"|";
				}
			}
		}
		if(area_attr_str==""){
			document.getElementById("area_attr").value = document.getElementById("area_attr_bak").value;
		}else{
			document.getElementById("area_attr").value = area_attr_str;
		}
		
		
		//分类拼串
		var class_attr_str = "";
		if(document.getElementById("class_id1").value!=""){
			class_attr_str += document.getElementById("class_id1").value + "|";
			if(document.getElementById("class_id2").value!=""){
				class_attr_str += document.getElementById("class_id2").value + "|";
				if(document.getElementById("class_id3").value!=""){
					class_attr_str += document.getElementById("class_id3").value + "|";
				}
			}
		
		}
		
		if(class_attr_str==""){
			document.getElementById("class_attr").value = document.getElementById("class_attr_bak").value;
		}else{
			document.getElementById("class_attr").value = class_attr_str;
		}
		
		
		
		if(document.getElementById("class_attr").value == ""){
				alert("请选择主营行业！");
				document.getElementById("sort1").focus();
				return false;
		}
	
	
	  var province = document.addForm.area_attr.value;
	  if(null == province || province == "")
	  {
	  	alert("公司所在地不能为空!");
		document.getElementById("province").focus();
	  	return false;
	  }

		
	  var user_name = document.addForm.user_name.value;
	  if(null == user_name || user_name == "")
	  {
	  	alert("登陆账号不能为空!");
	  	document.getElementById("user_name").focus();
	  	return false;
	  }
	  
	  var passwd = document.addForm.passwd.value;
	  if(null == passwd || passwd == "")
	  {
	  	alert("登陆密码不能为空!");
	  	document.getElementById("passwd").focus();
	  	return false;
	  }
	  	  	  	  	  	  	  
		
	  var company_address = document.addForm.business_addr.value;
	  if(null == company_address || company_address == "")
	  {
	  	alert("经营地址不能为空!");
	  	document.getElementById("business_addr").focus();
	  	return false;
	  }
	  
	 
	  var a = document.addForm.cust_supply.value;
	  var b = document.addForm.cust_stock.value;
		var a_b = a+b;
	  if(null == a_b || a_b == ""){
	  	alert("主营方向不能为空！");
	  	return false;	
	  }
	  var enterprise_scope = document.addForm.cust_key.value;
	  if(null == enterprise_scope || enterprise_scope == "")
	  {
	  	alert("公司关健词不能为空!");
	  	document.getElementById("cust_key").focus();
	  	return false;
	  }
	  var enterprise_size_code = document.addForm.main_product.value;
	  if(null == enterprise_size_code || enterprise_size_code == "")
	  {
	  	alert("公司经营范围不能为空!");
	  	document.getElementById("main_product").focus();
	  	return false;
	  }
	  
		
		var editor_data = CKEDITOR.instances.cust_desc.getData();
	
		if(editor_data.length==0){
			alert( "请填写产品的公司简介！" );
			CKEDITOR.instances.cust_desc.focus();
			return false;
		}
	 
	  
	
		//真实姓名不能为空
	  var realname = document.addForm.contact_name.value;
	  if(null == realname || realname == "")
	  {
	  	alert("真实姓名不能为空!");
	  	document.addForm.contact_name.focus();
	  	return false;
	  }else if(checkDenyWords(realname)){
			alert("真实姓名含有非法字符!");
	  	document.addForm.contact_name.focus();
	  	return false;
		}
	  
	  var job = document.addForm.jobs.value;
	  if(null == job || job == "")
	  {
	  	alert("职位不能为空!");
	  	document.getElementById("jobs").focus();
	  	return false;
	   }
	  var email = document.addForm.email.value;
	  var chemEmails=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	  if(null == email || email == "")
	  {
	  	alert("邮箱不能为空!");
	  	document.getElementById("email").focus();
	  	return false;
	  }else if (!chemEmails.test(email)){
			alert("Email的格式不正确");
			document.getElementById("email").focus();
			return false;
	  }
	 
	 
	  
	  var group_contact_phone = document.addForm.phone.value;
	  if(null == group_contact_phone  )
	  {
	  	alert("固定电话不能为空!");
	  	document.getElementById("phone").focus();
	  	return false;
	  }
		
	   //把传真号码和区号拼接在一起
	 
	  
	  var phone = document.addForm.cellphone.value;
	  if(null == phone || phone == "")
	  {
	  	alert("手机号码不能为空!");
	  	document.getElementById("cellphone").focus();
	  	return false;
	  }
		
	
	
	  //获取公司经营范围需要过来html代码的控件
	  document.getElementById("main_product").value = document.getElementById("main_product").value.replace(/<\/?[^>]+>/g,""); //去除HTML tag
      document.getElementById("main_product").value = document.getElementById("main_product").value.replace(/[ | ]*\n/g,"\n"); //去除行尾空白
      document.getElementById("main_product").value = document.getElementById("main_product").value.replace(/\n[\s| | ]*\r/g,"\n"); //去除多余空行
	  
	   
		

	  

}



//========================用户名验证start ===========================







function ifCheck(){
	
	if(document.getElementById("client_status5").checked == true){
		
		document.getElementById("client_status1").disabled=true;
		document.getElementById("client_status2").disabled=true;
		document.getElementById("client_status3").disabled=true;
		document.getElementById("client_status4").disabled=true;
	}else {
		
		document.getElementById("client_status1").disabled=false;
		document.getElementById("client_status2").disabled=false;
		document.getElementById("client_status3").disabled=false;
		document.getElementById("client_status4").disabled=false;
	}
}



//验证主营方向
function showSpan(val){
	if(val==1){
		document.getElementById('xiaoshou').style.display='block';
		document.getElementById('caigou').style.display='none';
	}
	if(val==0){
		document.getElementById('xiaoshou').style.display='none';
		document.getElementById('caigou').style.display='block';
	}
	if(val==2){
		document.getElementById('xiaoshou').style.display='block';
		document.getElementById('caigou').style.display='block';
	}
}




function choseForm(val)
{
	if(val == "custButton"){
	document.getElementById('custInfo').style.display='block';
	document.getElementById('userInfo').style.display='none';
	document.getElementById('levelInfo').style.display='none';
	}
	if(val == "userButton"){
	document.getElementById('custInfo').style.display='none';
	document.getElementById('userInfo').style.display='block';
	document.getElementById('levelInfo').style.display='none';
	}
	if(val == "levelButton"){
	document.getElementById('custInfo').style.display='none';
	document.getElementById('userInfo').style.display='none';
	document.getElementById('levelInfo').style.display='block';
	}	
}


 
 


 